package com.pearadmin.system.controller;

import com.github.pagehelper.PageInfo;
import com.pearadmin.system.domain.SysAxisShake;
import com.pearadmin.common.tools.string.Convert;
import com.pearadmin.common.web.base.BaseController;
import com.pearadmin.common.web.domain.request.PageDomain;
import com.pearadmin.common.web.domain.response.Result;
import com.pearadmin.common.web.domain.response.module.ResultTable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import com.pearadmin.system.service.ISysAxisShakeService;

import javax.annotation.Resource;
import java.util.List;

/**
 * 动态更新主轴震动Controller
 * 
 * @author Ryan
 * @date 2021-04-07
 */
@RestController
@RequestMapping("/system/axisShake")
public class SysAxisShakeController extends BaseController
{
    private String prefix = "system/axisShake";

    @Autowired
    private ISysAxisShakeService sysAxisShakeService;

    @GetMapping("/main")
    @PreAuthorize("hasPermission('/system/axisShake/main','system:axisShake:main')")
    public ModelAndView main()
    {
        return jumpPage(prefix + "/main");
    }

    /**
     * 查询动态更新主轴震动列表
     */
    @ResponseBody
    @GetMapping("/data")
    @PreAuthorize("hasPermission('/system/axisShake/data','system:axisShake:data')")
    public ResultTable list(@ModelAttribute SysAxisShake sysAxisShake, PageDomain pageDomain)
    {
        PageInfo<SysAxisShake> pageInfo = sysAxisShakeService.selectSysAxisShakePage(sysAxisShake,pageDomain);
        return pageTable(pageInfo.getList(),pageInfo.getTotal());
    }

    /**
     * 主轴趋势图数据（从redis中获取）
     */
    @ResponseBody
    @GetMapping("/getData")
    @PreAuthorize("hasPermission('/system/axisShake/getData','system:axisShake:getData')")
    public SysAxisShake getRedisShake(String id){
        SysAxisShake sysAxisShake=sysAxisShakeService.getRedisShakeById(id);

         return sysAxisShake;
    }

    /**
     * 新增动态更新主轴震动
     */
    @GetMapping("/add")
    @PreAuthorize("hasPermission('/system/axisShake/add','system:axisShake:add')")
    public ModelAndView add()
    {
        return jumpPage(prefix + "/add");
    }

    /**
     * 新增保存动态更新主轴震动
     */
    @ResponseBody
    @PostMapping("/save")
    @PreAuthorize("hasPermission('/system/axisShake/add','system:axisShake:add')")
    public Result save(@RequestBody SysAxisShake sysAxisShake)
    {
        return decide(sysAxisShakeService.insertSysAxisShake(sysAxisShake));
    }

    /**
     * 修改动态更新主轴震动
     */
    @GetMapping("/edit")
    @PreAuthorize("hasPermission('/system/axisShake/edit','system:axisShake:edit')")
    public ModelAndView edit(String id, ModelMap mmap)
    {
        SysAxisShake sysAxisShake = sysAxisShakeService.selectSysAxisShakeById(id);
        mmap.put("sysAxisShake", sysAxisShake);
        return jumpPage(prefix + "/edit");
    }

    /**
     * 修改保存动态更新主轴震动
     */
    @ResponseBody
    @PutMapping("/update")
    @PreAuthorize("hasPermission('/system/axisShake/edit','system:axisShake:edit')")
    public Result update(@RequestBody SysAxisShake sysAxisShake)
    {
        return decide(sysAxisShakeService.updateSysAxisShake(sysAxisShake));
    }

    /**
     * 删除动态更新主轴震动
     */
    @ResponseBody
    @DeleteMapping( "/batchRemove")
    @PreAuthorize("hasPermission('/system/axisShake/remove','system:axisShake:remove')")
    public Result batchRemove(String ids)
    {
        return decide(sysAxisShakeService.deleteSysAxisShakeByIds(Convert.toStrArray(ids)));
    }

    /**
     * 删除
     */
    @ResponseBody
    @DeleteMapping("/remove/{id}")
    @PreAuthorize("hasPermission('/system/axisShake/remove','system:axisShake:remove')")
    public Result remove(@PathVariable("id") String id)
    {
        return decide(sysAxisShakeService.deleteSysAxisShakeById(id));
    }
}
